{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "读取abc.txt文件内容\n",
      "dgjkhgkjshgkzsh省得浪费时间看个大概楼上的几个老师对接654654654654654\n"
     ]
    }
   ],
   "source": [
    "from abc import abstractmethod,ABCMeta\n",
    "class subject(metaclass=ABCMeta):\n",
    "    @abstractmethod\n",
    "    def get_content(self):\n",
    "        pass\n",
    "class realsubject(subject):\n",
    "    def __init__(self,filename):\n",
    "        self.filename=filename\n",
    "        print('读取%s文件内容'%filename)\n",
    "        f=open(filename,encoding='utf-8')\n",
    "        self.content=f.read()\n",
    "        f.close()\n",
    "    def get_content(self):\n",
    "        return self.content\n",
    "    def set_content(self,content):\n",
    "        f=open(self.filename,'w')\n",
    "        f.write(content)\n",
    "        f.close()\n",
    "class proxya(subject):\n",
    "    def __init__(self,filename):\n",
    "        self.subj=realsubject(filename)\n",
    "    def get_content(self):\n",
    "        return self.subj.get_content()\n",
    "class proxyb(subject):\n",
    "    def __init__(self,filename):\n",
    "        self.filename=filename\n",
    "        self.subj=None\n",
    "    def get_content(self):\n",
    "        if not self.subj:\n",
    "            self.subj=realsubject(self.filename)\n",
    "        return self.subj.get_content()\n",
    "class proxyc(subject):\n",
    "    def __init__(self,filename):\n",
    "        self.subj=realsubject(filename)\n",
    "    def get_content(self):\n",
    "        return self.get_content()\n",
    "    def set_content(self):\n",
    "        raise PermissionError\n",
    "b=proxyb('abc.txt')\n",
    "print(b.get_content())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
